/**
 * 版权所有：恒生电子股份有限公司 保留所有权利
 * 版本： 1.0
 * ******************************************
 * Copyright (c)  by Hundsun ,Ltd.
 * All right reserved.
 * Last version:  1.0
 */
package com.hundsun.tbsp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import org.springframework.core.Ordered;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.client.RestTemplate;
import org.tinygroup.servicehandlermapping.handlermapping.TinyServiceHandlerMapping;
import org.tinygroup.servicehandlermapping.loader.ServiceComponentLoader;
import org.tinygroup.tinystarter.TinyLifecycle;

/*********************************************************
 * 文件名称：SpringCloundApplication.java
 * 系统名称：交易银行系统V1.0
 * 模块名称：com.hundsun.tbsp
 * 功能说明：
 * 开发人员：yupan18551
 * 开发时间：2018-06-01 9:41
 * 修改记录：程序版本	修改日期	修改人员	修改单号	修改说明
 *********************************************************/
@EnableEurekaClient
@SpringBootApplication
@ImportResource(value = {
        "classpath*:spring.beans.xml",
        "classpath*:aop.config.beans.xml",
        "classpath*:asynspring.beans.xml",
        "classpath*:mybatis.config.beans.xml",
        "classpath*:redis.config.beans.xml",
        "classpath*:zookeeper.config.beans.xml",
        "classpath*:mongodb.beans.xml",
        "classpath*:Application.beans.xml",
        "classpath*:spring.asyn.beans.xml"
})
public class CoreSpringCloundApplication extends SpringBootServletInitializer implements WebApplicationInitializer {

    public static void main(String[] args) {
        SpringApplication.run(CoreSpringCloundApplication.class);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        builder.sources(this.getClass());
        return super.configure(builder);
    }

    @Bean
    public TinyServiceHandlerMapping tinyServiceHandlerMapping() {
        TinyServiceHandlerMapping tinyServiceHandlerMapping = new TinyServiceHandlerMapping();
        tinyServiceHandlerMapping.setServiceComponentLoader(new ServiceComponentLoader());
        tinyServiceHandlerMapping.setOrder(Ordered.HIGHEST_PRECEDENCE);
        return tinyServiceHandlerMapping;
    }

    @Bean
    public TinyLifecycle tinyLifecycle() {
        return new TinyLifecycle();
    }

    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate();
    }
}
